//
//  BaseButton.m
//  New
//
//  Created by dlios on 15-7-16.
//  Copyright (c) 2015年 yangTao. All rights reserved.
//

#import "BaseButton.h"

@implementation BaseButton
-(instancetype)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    if (self) {
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        
        if ([@"on"isEqualToString:[user objectForKey:@"night"]]) {
          
            [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

        }
        else{
            [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
           
        }
        
        NSNotificationCenter *notification = [NSNotificationCenter defaultCenter];
        [notification addObserver:self selector:@selector(changeNight:) name:@"changeNight" object:nil];
        

        
        
    }
    return self;
}
-(void)changeNight:(NSNotification *)notification{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user setObject:(NSString *)[notification object] forKey:@"night"];
    
    if ([@"on"isEqualToString:[user objectForKey:@"night"]]) {
        
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
    }
    else{
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
    }
    
    
    
}
-(void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"changeNight" object:nil];
}

@end
